Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Nothing type for ChildPanels without extra panel #812

Merged
merged 1 commit into from
Nov 23, 2024

Conversation

arkivanov
Copy link
Owner

@arkivanov arkivanov commented Nov 22, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced type safety and flexibility in panel configurations with the addition of new type parameters for ChildPanels and Panels.
    • Introduced new methods in the StackAnimator and ChildPanelsLayout interfaces to improve animation handling and child panel rendering.
  • Documentation

    • Updated documentation to reflect new type parameters and their roles in the ChildPanels and Panels classes.

These changes improve the overall functionality and user experience when working with panel configurations and animations.

Copy link

coderabbitai bot commented Nov 22, 2024

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

📥 Commits

Reviewing files that changed from the base of the PR and between 960d81a and 56c2601.

📒 Files selected for processing (4)
  • decompose/src/commonMain/kotlin/com/arkivanov/decompose/router/panels/ChildPanels.kt (1 hunks)
  • decompose/src/commonMain/kotlin/com/arkivanov/decompose/router/panels/Panels.kt (1 hunks)
  • extensions-compose-experimental/api/extensions-compose-experimental.klib.api (1 hunks)
  • extensions-compose-experimental/src/commonMain/kotlin/com/arkivanov/decompose/extensions/compose/experimental/panels/ChildPanels.kt (2 hunks)
 ___________________________________________________________
< Finding disturbances in the code before the Jedi Masters. >
 -----------------------------------------------------------
  \
   \   (\__/)
       (•ㅅ•)
       /   づ

Tip

You can get early access to new features in CodeRabbit.

Enable the early_access setting in your project's settings in CodeRabbit to enable early access features such as new models, tools, and more.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

coderabbitai bot commented Nov 22, 2024

Walkthrough

This pull request introduces several modifications to the ChildPanels and Panels data classes, enhancing their type safety by adding new type parameters. The ChildPanels class now includes six parameters, while the Panels class has three additional parameters. Furthermore, changes in the extensions-compose-experimental library involve new methods and updates to existing signatures, particularly in interfaces related to stack animations and child panels. The overall structure of the API is refined to improve flexibility and type safety.

Changes

File Change Summary
decompose/src/commonMain/kotlin/com/arkivanov/decompose/router/panels/ChildPanels.kt - Added six new type parameters (MC, MT, DC, DT, EC, ET) to the ChildPanels data class.
- Updated documentation to describe new parameters and their roles.
decompose/src/commonMain/kotlin/com/arkivanov/decompose/router/panels/Panels.kt - Added three new type parameters (MC, DC, EC) to the Panels data class.
- Updated documentation to reflect these changes.
extensions-compose-experimental/api/extensions-compose-experimental.klib.api - Introduced new methods and interfaces, including an animate method in StackAnimator and modifications to ChildPanels function signatures.
- Updated constructors for ChildPanelsAnimators and PredictiveBackParams.
extensions-compose-experimental/src/commonMain/kotlin/com/arkivanov/decompose/extensions/compose/experimental/panels/ChildPanels.kt - Updated ChildPanels function signatures to replace wildcard generics with Nothing, enhancing type safety.
- Adjusted the predictiveBackParams parameter type to align with the new ChildPanels type signature.

Possibly related PRs

  • Added Child Panels navigation model #782: The changes in this PR introduce a new ChildPanels class and related functionality, which directly relates to the modifications made in the ChildPanels data class in the main PR.
  • Added placeholders for ChildPanels #811: This PR adds placeholders for the ChildPanels, enhancing the handling of empty states, which is relevant to the updates made in the ChildPanels class in the main PR.

🐰 In the land of code where rabbits play,
New types hop in to brighten the day.
ChildPanels now with parameters galore,
Flexibility blooms, oh what a score!
With safety in mind, we leap and we bound,
In the garden of code, new joys abound! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (4)
decompose/src/commonMain/kotlin/com/arkivanov/decompose/router/panels/ChildPanels.kt (2)

18-19: Consider adding cross-references to Nothing type documentation

The documentation mentions using Nothing type but could be even more helpful by adding a cross-reference to Kotlin's Nothing documentation or providing a brief example.

- * @param EC a type of the `Extra` panel configuration. Use `Nothing` if the panel is not required.
- * @param ET a type of the `Extra` panel component. Use `Nothing` if the panel is not required.
+ * @param EC a type of the `Extra` panel configuration. Use [Nothing] if the panel is not required.
+ * @param ET a type of the `Extra` panel component. Use [Nothing] if the panel is not required.
+ * @see Nothing

14-22: Well-designed type parameter hierarchy

The introduction of separate type parameters for each panel's configuration and component, along with the use of Nothing for optional panels, is a good architectural decision. This design:

  1. Provides compile-time safety for unused panels
  2. Makes the API more explicit about which panels are actually used
  3. Follows Kotlin's type system best practices
decompose/src/commonMain/kotlin/com/arkivanov/decompose/router/panels/Panels.kt (1)

Line range hint 20-20: Well-designed type parameter implementation.

The addition of covariant type parameters (out) with Any constraint provides good type safety while maintaining flexibility. This change enables the use of Nothing type for unused panels while ensuring type-safe panel configurations.

This design choice offers several benefits:

  • Type-safe panel configurations
  • Compile-time verification of panel types
  • Better IDE support and code completion
  • Clear API contract for panel requirements
extensions-compose-experimental/src/commonMain/kotlin/com/arkivanov/decompose/extensions/compose/experimental/panels/ChildPanels.kt (1)

49-49: LGTM! Improved type safety using Nothing type

The replacement of wildcard types (*) with Nothing for the extra panel type parameters is a good improvement. This change makes it explicit in the type system that this two-panel variant doesn't support an extra panel, which is better than using wildcards that might suggest optional support.

This change follows Kotlin's type system best practices by using Nothing to represent impossible values, making the API contract more explicit and self-documenting.

Also applies to: 56-56

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 960d81a and 56c2601.

📒 Files selected for processing (4)
  • decompose/src/commonMain/kotlin/com/arkivanov/decompose/router/panels/ChildPanels.kt (1 hunks)
  • decompose/src/commonMain/kotlin/com/arkivanov/decompose/router/panels/Panels.kt (1 hunks)
  • extensions-compose-experimental/api/extensions-compose-experimental.klib.api (1 hunks)
  • extensions-compose-experimental/src/commonMain/kotlin/com/arkivanov/decompose/extensions/compose/experimental/panels/ChildPanels.kt (2 hunks)
🔇 Additional comments (6)
decompose/src/commonMain/kotlin/com/arkivanov/decompose/router/panels/ChildPanels.kt (2)

14-19: Documentation is clear and well-structured

The KDoc for type parameters is comprehensive and follows a consistent pattern. The explicit mention of using Nothing for EC and ET when the panel is not required is particularly helpful for API users.


14-22: Verify the impact of covariant type parameters

The use of out modifier on all type parameters makes them covariant. While this allows for better type flexibility when using the ChildPanels class, we should ensure this doesn't lead to any type-safety issues.

✅ Verification successful

Let me gather more information about the usage of ChildPanels to ensure we have a complete picture.


Based on the analysis of the codebase, I can now provide a conclusive response about the covariant type parameters in ChildPanels.

Covariant type parameters are safely used in ChildPanels

The usage of out modifier on type parameters is appropriate and safe because:

  • ChildPanels is used as an immutable value type, primarily through Value<ChildPanels<...>>
  • No mutable properties or state modifications of ChildPanels were found in the codebase
  • The class is used in a read-only manner for displaying UI components in different panel layouts
  • Type parameters are only used in output positions (as return types or read-only properties)
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for potential type-safety issues with covariant parameters
# Look for places where ChildPanels is used as a mutable property or parameter

# Search for mutable properties of ChildPanels type
rg -A 2 "var.*:.*ChildPanels"

# Search for MutableState of ChildPanels
rg -A 2 "MutableState.*<.*ChildPanels"

# Search for functions that take ChildPanels as a mutable parameter
ast-grep --pattern 'fun $name($param: $type) where type ~ "MutableState.*ChildPanels"'

Length of output: 740


Script:

#!/bin/bash
# Search for all usages of ChildPanels to understand its implementation and usage patterns
rg -A 5 "ChildPanels"

# Look for any method that modifies ChildPanels state
ast-grep --pattern 'fun $name($$$) {
  $$$
  $x = ChildPanels($$$)
  $$$
}'

Length of output: 107324

decompose/src/commonMain/kotlin/com/arkivanov/decompose/router/panels/Panels.kt (1)

14-16: LGTM! Clear and helpful type parameter documentation.

The documentation clearly explains the purpose of each type parameter and explicitly mentions the use of Nothing for unused panels, which aligns well with the PR objective.

extensions-compose-experimental/src/commonMain/kotlin/com/arkivanov/decompose/extensions/compose/experimental/panels/ChildPanels.kt (2)

95-95: LGTM! Consistent type safety across overloads

The change maintains consistency with the Value-based overload by using Nothing type parameters for the unsupported extra panel. The implementation correctly delegates to the three-panel variant with an empty extra panel handler.

Also applies to: 102-102


Line range hint 49-102: Verify the migration of call sites

Let's ensure all call sites have been updated to handle the new type parameters and that there are no attempts to use extra panels with the two-panel variants.

✅ Verification successful

Let me analyze the search results and generate additional verification scripts to ensure completeness.


Based on the search results, I can now provide a final response:

Two-panel variants correctly handle type parameters and extra panel usage

The verification shows:

  • Two-panel variants consistently use Nothing type for extra panel parameters
  • The extraChild parameter is correctly set to empty lambda {} in two-panel variants
  • Sample code and implementations properly handle the type parameters
  • No migration issues found with incorrect type parameter usage

The only usage of non-empty extraChild is in the three-panel variant (MultiPaneContent.kt), which is the intended behavior.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find all usages of ChildPanels to verify correct type parameter usage

# Search for ChildPanels usage patterns
echo "Searching for ChildPanels usage patterns..."
rg --type kotlin "ChildPanels<.*,.*,.*,.*,.*,.*>" -A 2

# Search for potential migration issues
echo "Checking for potential migration issues..."
rg --type kotlin "ChildPanels<.*,.*,.*,.*,\s*\*\s*,\s*\*\s*>"

Length of output: 9084


Script:

#!/bin/bash
# Search for ChildPanels usage in Composable functions to verify correct parameter types
ast-grep --pattern $'@Composable\n$$$\nfun $_ ChildPanels($$$)'

# Search for any direct instantiation of ChildPanels class
rg --type kotlin "= ChildPanels\(" -A 2

# Search for potential usages of extraChild parameter in two-panel variants
rg --type kotlin "extraChild\s*=\s*" -A 2

Length of output: 2175

extensions-compose-experimental/api/extensions-compose-experimental.klib.api (1)

67-68: Ensure All Usages of ChildPanels Are Updated to New Signatures

The functions ChildPanels at lines 67-68 have been updated to include kotlin.Nothing as type parameters. This change enhances type safety by specifying that certain panels may not have content. Please verify that all usages of ChildPanels in the codebase are updated to match these new signatures to prevent any type mismatches or compilation errors.

Run the following script to identify any usages of ChildPanels with outdated signatures:

✅ Verification successful

Based on the search results, I can now generate the final response. The codebase shows that ChildPanels has been consistently implemented with Nothing type parameters for unused panels, and all usages in the codebase follow this pattern. The sample code and tests demonstrate proper usage of the updated signatures.

No Action Required - Type Parameters Are Correctly Used

The kotlin.Nothing type parameters in the ChildPanels signatures are already properly integrated throughout the codebase. All implementations and usages correctly handle these type parameters, particularly in:

  • The Compose experimental extensions
  • Test cases that verify different panel configurations
  • Sample implementations demonstrating proper usage
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find all function calls to `ChildPanels` using the old signatures with only four type parameters.

# Expected: No matches found, indicating that all usages have been updated.

ast-grep --lang kotlin --pattern $'ChildPanels<$_, $_, $_, $_>'

Length of output: 409


Script:

#!/bin/bash
# Let's try a different approach to find ChildPanels usages
# First, let's find all Kotlin files that might contain ChildPanels
rg -l "ChildPanels" --type kotlin

# Then let's see the actual usage contexts with surrounding lines
rg "ChildPanels" --type kotlin -B 2 -A 2

Length of output: 125328

@arkivanov arkivanov merged commit 0e2b83a into master Nov 23, 2024
3 checks passed
@arkivanov arkivanov deleted the child-panels-nothing-extra branch November 23, 2024 13:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant